package cn.skyquant.quant4j.service.boot.web.controller;

import cn.skyquant.quant4j.api.dto.ResultDTO;
import cn.skyquant.quant4j.api.enums.BorkerType;
import cn.skyquant.quant4j.api.order.AccountOrderHisDTO;
import cn.skyquant.quant4j.api.order.OrderService;
import cn.skyquant.quant4j.service.boot.model.authority.RoleAuthority;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/order")
//@RoleAuthority(roleNames = {RoleAuthority.administrator, RoleAuthority.client})
public class OrderController {

    @Resource
    OrderService orderService;

    @RequestMapping(value = "/getMaxDate", method = RequestMethod.GET)
    @ResponseBody
    public ResultDTO<Long> getMaxDate(
            @RequestParam(required = true) String accountCode,
            @RequestParam(required = true) String borkerType,
            @RequestParam(required = true) String symbol) {
        BorkerType bt = BorkerType.valueOf(borkerType);
        return orderService.getMaxDate(accountCode,bt,symbol);
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    @ResponseBody
    public ResultDTO<Void> insert(
             String id,
             String accountId,
             String borkerType,
             String symbol,
             String label,
             double amount,
             String comment,
             String command,
             double openPrice,
             double closePrice,
             double sl,
             double tp,
             long creationTime,
             long fillTime,
             long closeTime,
             double commission,
             double profit
    ) {
        AccountOrderHisDTO accountOrderHisDTO = new AccountOrderHisDTO();
        accountOrderHisDTO.id = id;
        accountOrderHisDTO.accountId = accountId;
        accountOrderHisDTO.borkerType = BorkerType.valueOf(borkerType);
        accountOrderHisDTO.symbol = symbol;
        accountOrderHisDTO.label = label;
        accountOrderHisDTO.amount = amount;
        accountOrderHisDTO.comment = comment;
        accountOrderHisDTO.command = command;
        accountOrderHisDTO.openPrice = openPrice;
        accountOrderHisDTO.closePrice = closePrice;
        accountOrderHisDTO.sl = sl;
        accountOrderHisDTO.tp = tp;
        accountOrderHisDTO.creationTime = creationTime;
        accountOrderHisDTO.fillTime = fillTime;
        accountOrderHisDTO.closeTime = closeTime;
        accountOrderHisDTO.commission = commission;
        accountOrderHisDTO.profit = profit;
        return orderService.insert(accountOrderHisDTO);
    }
}
